package org.TCPcase5;


import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Server {
    public static void main(String[] args) throws IOException {
//       利用线程池来优化case的代码
        ServerSocket socket = new ServerSocket(10086);
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(
                3,
                9,
                60,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(2),
                Executors.defaultThreadFactory()
                );

        while (true) {
            Socket accept = socket.accept();
            poolExecutor.submit(new MyRunnable(accept));
        }
    }
}
